home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
sos3-2.lha
/
src
/
demo
/
demo_main.c
Wrap
C/C++ Source or Header
|
1992-01-23
|
8KB
|
346 lines
/* --------------------------------------------------------------------------
* Copyright 1992 by Forschungszentrum Informatik (FZI)
*
* You can use and distribute this software under the terms of the licence
* you should have received along with this program.
* If not or if you want additional information, write to
* Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
* D-7500 Karlsruhe 1, Germany.
* --------------------------------------------------------------------------
*/
// **************************************************************************
// Module demo ??/??/89 Joerg Wienke
//
// **************************************************************************
// Simple non-graphic tool to inspect the meta-database (small test program)
// **************************************************************************
#include <stream.h>
#include <string.h>
#include "sos.h"
#include "smg.h"
#include "mta_use.h"
#include "dir_use.h"
// *******
smg_String type_kind (sos_Type type)
{
if (type.has_type (sos_Union_type_type))
return "Union ";
if (type.has_type (sos_Typedef_type_type))
return "Typedef ";
if (type.has_type (sos_Extern_type_type))
return "Extern ";
if (type.has_type (sos_Class_type_type))
return "Class ";
if (type.has_type (sos_Enum_type_type))
return "Enum ";
return " ";
}
// *******
void get_meth (sos_Method_List ml)
{
agg_iterate (ml, sos_Method m)
{ cout << " ";
if (m.get_is_static() == TRUE)
cout << "static ";
cout << m.get_result_type ().make_type_name() << " "
<< m.get_name() << " ";
sos_Param_List pl = m.get_params ();
cout << "(";
sos_Bool is_first = TRUE;
agg_iterate (pl, sos_Param p)
{ if (is_first)
is_first = FALSE;
else
cout << ", ";
cout << p.get_type_name().make_type_name();
}
agg_iterate_end (pl, p);
cout << ");\n";
}
agg_iterate_end (ml, m);
}
// *******
void type_menu (int& choice, sos_Schema_module& sm, sos_String& str)
{ smg_String t_kind;
sos_Type type;
sos_Type_table type_table;
cout << "\f";
type_table = sm.get_type_table ();
type = type_table [str];
if (type.has_type (sos_Class_type_type))
{
cout << "class " << str;
sos_Class_type ct = sos_Class_type::make(type);
// print generic parameters
// ========================
sos_Gen_param_List gpl;
gpl = ct.get_gen_params ();
if (gpl != NO_OBJECT)
{ cout << "<";
sos_Bool is_first = TRUE;
agg_iterate (gpl, sos_Gen_param gp)
{ if (is_first)
is_first = FALSE;
else
cout << ", ";
cout << gp.get_name ();
}
agg_iterate_end (gpl, gp);
cout << "> ";
}
// print parameters
// ================
sos_Param_List pl;
pl = ct.get_create_params ();
if (pl != NO_OBJECT)
{ cout << "(";
sos_Bool is_first = TRUE;
agg_iterate (pl, sos_Param p)
{ if (is_first)
is_first = FALSE;
else
cout << ", ";
cout << p.get_type_name ().make_type_name();
sos_String n = p.get_name();
if (n != NO_OBJECT)
cout << " " << n;
}
agg_iterate_end (pl, p);
cout << ") ";
}
// print super_classes
// ===================
sos_Type_name_List tnl;
tnl = ct.get_super_classes ();
sos_Bool is_first = TRUE;
agg_iterate (tnl, sos_Type_name tn)
{ if (is_first)
{ is_first=FALSE;
cout << ": ";
}
else
cout << ", ";
cout << tn.make_type_name();
}
agg_iterate_end (tnl, tn);
// ===========================
cout << "\n{\n";
get_meth (ct.get_methods());
get_meth (ct.get_comp_methods());
get_meth (ct.get_static_methods());
cout << "}\n";
}
else if (type.has_type (sos_Union_type_type))
{
sos_Union_type ut = sos_Union_type::make(type);
sos_Type_name_List lt;
cout << "union " << str << "\n{\n";
lt = ut.get_uniteds ();
agg_iterate (lt, sos_Type_name tn)
{ cout << " " << tn.make_type_name() << ";\n";
}
agg_iterate_end (lt, tn);
cout << "}\n";
}
else if (type.has_type (sos_Typedef_type_type))
{
sos_Typedef_type tt = sos_Typedef_type::make(type);
cout << "typedef "
<< "<" << tt.get_type_name ().make_type_name() << ">"
<< " " << str << "\n";
}
else if (type.has_type (sos_Extern_type_type))
{
cout << "\n\n no further information \n";
}
else if (type.has_type (sos_Enum_type_type))
{
sos_Enum_type et = sos_Enum_type::make(type);
sos_String_List sl;
cout << " enum " << str << " {";
sl = et.get_literals ();
sos_Bool is_first = TRUE;
agg_iterate (sl, sos_String s)
{ if (is_first)
is_first = FALSE;
else
cout << ", ";
cout << s;
}
agg_iterate_end (sl, s);
cout << "};";
}
cout << "\n\n (0) RETURN\n";
cout << "\n\n CHOICE: ";
cin >> choice;
if (choice == 0)
{ sos_Imports imports = sm.get_imports();
agg_iterate (imports, sos_Schema_module imported)
{ imported.container().close ();
}
agg_iterate_end (imports, imported);
sm.container ().close ();
return;
}
}
// *******
void schema_menu (int& choice, sos_Schema_module& sm, sos_String& str)
{ sos_Type_table tt;
sos_String a[100];
cout << "\f";
sm.open_imports ();
tt = sm.get_type_table ();
int i = 1;
agg_iterate_association (tt, sos_String name, sos_Type tp)
{ char is [10];
a[i] = name;
sprintf (is, "(%d) ", i);
#ifdef ATT
char _is [12];
sprintf (_is, "%11s", is);
cout << _is
#else
cout << form("%11s",is)
#endif
<< type_kind (tp) << name << "\n";
i++;
}
agg_iterate_association_end (tt, name, tp);
cout << "\n (0) RETURN\n";
cout << "\n CHOICE: ";
cin >> choice;
if (choice == 0)
{ sm.close_imports ();
sm.container().close ();
}
else
str = a[choice];
}
// *******
void schema_dir_menu (int& choice,
sos_Schema_module_Directory& sd, sos_Schema_module& sm)
{ sos_Container sm_container;
sos_String a[10];
sos_Imports imports;
cout << "\f"; // clear screen
int i = 1;
agg_iterate_association (sd, sos_String name, sos_Schema_module mdl)
{ a[i] = name;
sos_Cstring sname = name.make_Cstring ();
#ifdef GNU
cout << "\n (" << i << ") " << form("%6s",sname);
#else
char _sname[7];
sprintf (_sname, "%6s", sname);
cout << "\n (" << i << ") " << _sname;
#endif
delete sname;
// imports
sm_container = mdl.container ();
sm_container.open ( READING, TESTING );
imports = mdl.get_imports();
cout << " imports: ";
agg_iterate (imports, sos_Schema_module imported)
{ cout << imported.get_name () << " ";
}
agg_iterate_end (imports, imported);
cout << "\n";
i++;
agg_iterate (imports, sos_Schema_module imported)
{ imported.container().close ();
}
agg_iterate_end (imports, imported);
sm_container.close ();
}
agg_iterate_association_end (sd, name, mdl);
cout << "\n\n (0) QUIT\n";
cout << "\n\n CHOICE: ";
cin >> choice;
if (choice != 0)
sm = sd [ a[choice] ];
}
// *******
main (int argc, char *argv[])
{
int choice1, choice2, choice3;
sos_String str;
sos_Schema_module sm;
sos_Schema_module_Directory sd;
sos_init (argc, argv);
sd = sos_Schema_module::schema_dir();
sd.container().open (READING, WAITING);
for (choice1 = 1; choice1; )
{ schema_dir_menu (choice1, sd, sm);
for (choice2 = 1; choice2 && choice1; )
{ schema_menu (choice2, sm, str);
for (choice3 = 1; choice3 && choice2; )
type_menu (choice3, sm, str);
}
}
sd.container().close ();
exit (0);
}